package com.nopay.dxdwphone.ui.ativity;

import android.os.Bundle;
import android.text.TextUtils;

import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.nopay.dxdwphone.base.BaseActivity;
import com.nopay.dxdwphone.bean.CommonResponse;
import com.nopay.dxdwphone.bean.request.FeedbackSaveRequest;

import com.nopay.dxdwphone.Constants;
import com.nopay.dxdwphone.R;
import com.nopay.dxdwphone.databinding.ActivityFeedBackBinding;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * @ProjectName: myVisualPhone
 * @Package: cn.cn.myvisualphone.ui.ativity
 * @ClassName: ForgetActivity
 * @Description: 更新用户姓名
 * @Author: anqi
 * @CreateDate: 2021/5/23 8:05
 * @UpdateUser: 更新者
 * @UpdateDate: 2021/5/23 8:05
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class FeedBackActivity extends BaseActivity<ActivityFeedBackBinding> {

    @Override
    protected void init(Bundle savedInstanceState, Object... preData) {
        binding.rlRoot.setPadding(0, getStatusBarHeight(FeedBackActivity.this), 0, 0);
        binding.ivBack.setOnClickListener(v -> mSwipeBackHelper.backward());

        binding.commitBtn.setOnClickListener(v -> {
            String position = binding.et.getText().toString().trim();
            if (TextUtils.isEmpty(position)){
                ToastUtils.showShort("请输入意见建议");
                return;
            }

            FeedbackSaveRequest bean = new FeedbackSaveRequest();
            bean.setPhone(SPUtils.getInstance().getString(Constants.SP_PHONE, ""));
            bean.setUserName(SPUtils.getInstance().getString(Constants.SP_USER_NAME, ""));
            bean.setOpinion(position);

            RequestBody body = getRequestBody(bean);
            api.doFeedbackSave(body).enqueue(new Callback<CommonResponse>() {
                @Override
                public void onResponse(Call<CommonResponse> call, Response<CommonResponse> response) {
                    if (response.body() != null) {
                        if (Constants.RESULT_OK.equals(response.body().getCode())) {
                            ToastUtils.showShort(response.body().getMsg());
                            mSwipeBackHelper.backward();
                        } else {
                            ToastUtils.showShort(response.body().getMsg());
                        }
                    }
                }

                @Override
                public void onFailure(Call<CommonResponse> call, Throwable t) {
                    ToastUtils.showShort(FeedBackActivity.this.getResources().getString(R.string.call_api_error));
                }
            });
        });

    }



}
